package org.hhchat.leetcode.math;

import java.util.ArrayList;
import java.util.List;

public class code415_easy {
    static class Solution {
        public String addStrings(String num1, String num2) {
            int p = num1.length()-1;
            int q = num2.length()-1;
            int c = 0;
            List<Integer> list = new ArrayList<>();
            StringBuilder stringBuilder = new StringBuilder();
            while (p >= 0 || q >= 0) {
                int a = p >= 0 ? Character.getNumericValue(num1.charAt(p--)) : 0;
                int b = q >= 0 ? Character.getNumericValue(num2.charAt(q--)) : 0;
                int sum = a + b + c;
                if (sum >= 10) {
                    c = 1;
                    sum -= 10;
                } else {
                    c = 0;
                }
                stringBuilder.insert(0, sum);
            }
            if(c!=0){
                stringBuilder.insert(0, c);
            }
            return stringBuilder.toString();
        }
    }
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.addStrings("123","1239"));
    }
}
